package cn.xjt.Consumer;

import cn.xjt.pojo.Dept;
import cn.xjt.service.DeptClientServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * 内容：
 *
 * @author
 * @date 2021/2/28-18:01
 */
@RestController
public class ConsumerController {

	@Autowired
	public RestTemplate restTemplate;

	@Autowired
	private DeptClientServer deptClientServer;
	
//	private static final String Url="http://localhost:8001";
	private static final String Url="http://springcloud-provider-dept";


	@RequestMapping(value = "/getAll",method = RequestMethod.GET)
	public List<Dept> getAll(){
		List<Dept> all = deptClientServer.getAll();
		return all;
	}

	@RequestMapping(value = "/getDept/{id}",method = RequestMethod.GET)
	public Dept getOne(@PathVariable("id") Long id){
		Dept dept = deptClientServer.getDept(id);
		return dept;
	}
	@RequestMapping(value = "/add",method = RequestMethod.POST)
	public String addDept(Dept dept){
		Boolean aBoolean = deptClientServer.addDept(dept);
		if (aBoolean){
			return "添加成功";
		}
		return "添加失败";
	}
}
